package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.entity.jz.AppIcon;
import com.sxbbc.common.core.enums.EventEnums;
import com.sxbbc.common.core.mapper.jz.AppIconMapper;
import com.sxbbc.common.core.service.IAppIconService;
import com.sxbbc.common.core.utils.BasePage;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * app图标信息表 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-05-14
 */
@Service
public class AppIconServiceImpl extends ServiceImpl<AppIconMapper, AppIcon> implements IAppIconService {

    @Override
    public Page<AppIcon> queryAppIconList(BasePage<AppIcon> page, AppIcon icon) {
        QueryWrapper<AppIcon> wrapper = new QueryWrapper<>();
        if (icon.getPosition() != null) {
            wrapper.eq("position",icon.getPosition());
        }
        wrapper.orderByDesc("sort");
        if (page.isPaging()) {
            super.page(page,wrapper);
        }else{
            List<AppIcon> list = super.list(wrapper);
            page.setRecords(list);
        }
        for (AppIcon a : page.getRecords()) {
            a.setTypeName(EventEnums.getName(a.getEvent()));
        }
        return page;
    }
}
